import time
from Base.Base import Base
from utils.data_helper import read_page_yaml


class Login(Base):
    def __init__(self, driver):
        super().__init__(driver)
        # self.elem_dict = read_page_yaml()
        self.elem_dict = read_page_yaml('login_page')
        self.elem_dict1 = read_page_yaml('mistake_page')

    def username(self, username):
        # 直接从字典取定位，无需多余逻辑
        self.send_keys(self.elem_dict['set_username'], username)

    def password(self, password):
        self.send_keys(self.elem_dict['set_password'], password)

    def login(self):
        self.click(self.elem_dict['set_denglu'])
    def dy4(self):
        return self.by(self.elem_dict1['set_dy4'])
    def dy5(self):
        return self.by(self.elem_dict1['set_dy5'])

    # 页面模块名（如登录页）
    def test_login(self, username, password):
        self.open_url('http://82.156.174.155:7009/roncoo-pay-web-boss/login')
        assert self.dy4()=='设为首页'
        time.sleep(1)
        self.username(username)# 用户名
        time.sleep(1)
        self.password(password)#密码
        time.sleep(1)
        self.login()#登录按钮
        time.sleep(2)
        assert self.dy5()=='龙果支付后台'